<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jspf/must/basePath.jspf" %>
<!--后台UI组件Start-->
<%@include file="/WEB-INF/jspf/zj/ligerui/LigerUI.jspf" %>
<%--<%@include file="/WEB-INF/jspf/zj/ligerui/LigerUI_form.jspf" %>--%>
<!--后台UI组件End-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link href="zj/uploadify/uploadify.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="zj/uploadify/jquery.uploadify.min.js"></script>
        <script src="dc_manager/base/food/series/js/Series_treeMenu.js" type="text/javascript"></script>
        <script type="text/javascript">
//-------------------------------全局变量-------------------------------------------------
            var UPDATE;
            var GRID;
            var ADD;
            $(function () {
                f_dc_base_food_series_menuTree("divID_Tree", f_food_series_choose);
                GRID = $("#divID_GRID").ligerGrid({
                    columns: [
                        {display: '系列', name: 'series_name', width: 90, align: 'left'}
                        , {display: '编号', name: 'food_code', width: 90, align: 'left'}
                        , {display: '菜名', name: 'food_name', width: 90, align: 'left'}
                        , {display: '价格', name: 'food_price', width: 90, align: 'left'}
                        , {display: '单位', name: 'unit_name', width: 90, align: 'left'}
                    ]
                    , usePager: false
                    , url: 'weixinkeji/dev/dc/base/food/s/manager.imy'
                    , width: '500'
                    , height: '97%'
                    , onSelectRow: f_foodimgManager
                });
                $("#toptoolbar").ligerToolBar({items: [
                        {text: '增加', click: add}
                        , {line: true}
                        , {text: '修改', click: update}
                        , {line: true}
                        , {text: '删除', click: dell}
                    ]});
                $("#file_upload").uploadify({
                    method: 'GET'
                    , swf: 'zj/uploadify/uploadify.swf'
                    , uploader: '<%=basePath%>weixinkeji/dev/dc/base/food/file/imgUpload.imy'
                    , fileTypeExts: '*.jpg;*.jpge;*.gif;*.png'
                    , fileSizeLimit: '2MB'
                    , onUploadStart: function (file) {
                        var id = $("#IMG_food_id").val();
                        if (id.length != 26) {
                            $("#file_upload").uploadify("cancel", "*");
                        }
                    }
                    , 'onUploadSuccess': function (file, data, response) {
                        var d = jQuery.parseJSON(data);
                        if (d.isok) {
                            $("#SHOW_IMG_ID").attr("src", d.path_saveName);
                            $("#SHOW_IMG_HREF_ID").attr("href", d.path_saveName);
                            GRID.reload();
                        }
                    }
                });
            });
//-------------------------------GRID列函数-----------------------------------------------
            //左树查询
            function f_food_series_choose(d, terget) {
                GRID.removeParm("nameOrCode");
                GRID.setParm("series_id", getMyNodeID("series_id", d.data));
                GRID.reload();
            }
            //右框查询
            function f_food_like_Select() {
                GRID.removeParm("series_id");
                var x = null == $("#IDNameORCode").val() ? "" : $("#IDNameORCode").val();
                GRID.setParm("nameOrCode", x);
                GRID.reload();
            }

            function f_foodimgManager(rowdata, rowid, rowobj) {
                var imgpath = null == rowdata.food_img ? "dc_manager/base/food/default.png" : rowdata.food_img;
                $("#SHOW_IMG_ID").attr("src", imgpath);
                $("#SHOW_IMG_HREF_ID").attr("href", imgpath);
                $("#showName").html("正在为展示【" + rowdata.food_name + "】");
                $("#IMG_food_id").val(rowdata.food_id);
                $("#file_upload").uploadify('settings', 'uploader', '<%=basePath%>weixinkeji/dev/dc/base/food/file/imgUpload.imy?foodID=' + rowdata.food_id);
            }
//-------------------------------增删改操作-----------------------------------------------
            function add() {
                ADD = openURL_Event("食物添加", ADD, "dc_manager/base/food/food_A.jsp", 400, 900, f_d);
                ADD.max();
                function f_d() {
                    ADD = null;
                    GRID.reload();
                }
            }
            function update() {
                var row = GRID.getSelectedRow();
                if (!row) {
                    msg_tip("错误", "请选择行");
                    return;
                } else if (row.food_id.length > 10) {
                    UPDATE = openURL_Event("食物修改", UPDATE, "weixinkeji/dev/dc/base/food/adu/update.imy?id=" + row.food_id, 400, 900, f_d);
                    UPDATE.max();
                }
                function f_d() {
                    UPDATE = null;
                    GRID.reload();
                }
            }
            function dell() {
                var rows = GRID.getSelectedRows();
                var ids = "";
                for (var i = 0; i < rows.length; i++) {
                    ids = ids + "," + rows[i].food_id;
                }
                ids = ids.substring(1);
                if (rows.length < 1) {
                    msg_tip("操作提示", "请选择行", 200, 50);
                    return;
                } else {
                    if (post_json("weixinkeji/dev/dc/base/food/adu/dell.imy", {"id": ids})) {
                        GRID.reload();
                        $("#SHOW_IMG_ID").attr("src", "");
                        $("#SHOW_IMG_HREF_ID").attr("href", "");
                        $("#showName").html("");
                        $("#IMG_food_id").val("");
                    }
                }
            }
        </script>
    </head>
    <body>  
        <div id="toptoolbar"></div> 
        <div>
            <div id="divID_Tree" style="float: left;width: 200px">---</div>
            <div id="divID_GRID" style="float: left"></div>
            <div style="float: left; margin-left: 10px;">
                <div id="divID_Select" style="margin: 5px; height: 100px">
                    <table style="font-size: 8px; height:50px;">
                        <tr>
                            <td>名称/编号</td><td><input id="IDNameORCode" name="nameOrCode" type="text" ></td>
                        </tr>
                        <tr>
                            <td></td><td><button onclick="f_food_like_Select();">查询</button></td>
                        </tr>
                    </table>

                </div>
                <div>

                    <p id="showName"></p>
                    <a id="SHOW_IMG_HREF_ID" href="#" target="_blank"><img alt="" id="SHOW_IMG_ID" src="" width="200px;" height="200px;"></a>
                    <p>
                        为了让图片更好好展示出来<p>请上传规格为正方形的图片</p>
                    </p>
                    <div id="queue" ></div>
                    <input id="file_upload" name="file_upload" type="file" multiple="true">
                    <input id="IMG_food_id" name="IMG_food_id" value="0" type="hidden">
                </div>
            </div>
        </div>
    </body>
</html>
